﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace PengSW.SqlServerTools
{
    public class IndexToBoolConverter : IValueConverter
    {
        public IndexToBoolConverter()
        {
            TrueIndex = 0;
            FalseIndex = 1;
            DefaultBool = true;
        }

        public int TrueIndex { get; set; }
        public int FalseIndex { get; set; }
        public bool DefaultBool { get; set; }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (DefaultBool == true)
                return (int)value == FalseIndex ? false : true;
            else
                return (int)value == TrueIndex ? true : false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (DefaultBool == true)
                return (bool)value == false ? FalseIndex : TrueIndex;
            else
                return (bool)value == true ? TrueIndex : FalseIndex;
        }
    }

    public class BoolToIndexConverter : IValueConverter
    {
        public int TrueIndex { get; set; }
        public int FalseIndex { get; set; }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return (bool)value ? TrueIndex : FalseIndex;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return (int)value == TrueIndex ? true : false;
        }
    }
}
